package com.zhuss.meeting.processor;

import com.zhuss.bean.bo.meeting.room.UpdateRoomBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.meeting.db.dao.ext.MeetingRoomDao;
import com.zhuss.meeting.db.entity.MeetingRoom;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/2/18 22:11
 */
@Component("roomUpdate")
public class RoomUpdate extends AbstractProcessor<Object, UpdateRoomBo> implements Processor<Object, UpdateRoomBo> {

    @Autowired
    private MeetingRoomDao roomDao;


    @Override
    public Object process(UpdateRoomBo updateRoomBo) throws WpsException {
        MeetingRoom meetingRoom = new MeetingRoom();
        meetingRoom.setRoomId(updateRoomBo.getRoomId());
        meetingRoom.setName(updateRoomBo.getName());
        meetingRoom.setLocation(updateRoomBo.getLocation());
        meetingRoom.setCapacity(updateRoomBo.getCapacity());
        meetingRoom.setDemand(updateRoomBo.getDemand());
        meetingRoom.setOther(updateRoomBo.getOther());
        meetingRoom.setCharges(updateRoomBo.getCharges());
        meetingRoom.setStatus(updateRoomBo.getStatus());

        meetingRoom.setModifierId(updateRoomBo.getConcurrentUserId());
        meetingRoom.setModifier(updateRoomBo.getConcurrentUserName());
        meetingRoom.setModifyTime(new Date());
        roomDao.updateByPrimaryKeySelective(meetingRoom);
        return null;
    }

    @Override
    public Object log(UpdateRoomBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.会务.key());
        record.setAction(LogActionEnum.会议室修改.key());
        record.setTargetId(param.getRoomId());
        record.setTargetName(param.getName());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(UpdateRoomBo updateRoomBo) throws WpsException {

    }
}
